package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.annotation.TingshuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.user.service.UserListenProcessService;
import com.atguigu.tingshu.vo.user.UserListenProcessVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

@Tag(name = "用户声音播放进度管理接口")
@RestController
@RequestMapping("api/user/userListenProcess")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserListenProcessApiController {

	@Autowired
	private UserListenProcessService userListenProcessService;

	@GetMapping("/getTrackBreakSecond/{trackId}")
	@TingshuLogin
	@Operation(summary = "查询已经登录用户的声音【暂停】描述")
	public Result getTrackBreakSecond(@PathVariable(value = "trackId") Long trackId) {

		BigDecimal breakSecond = userListenProcessService.getTrackBreakSecond(trackId);

		return Result.ok(breakSecond);

	}

	@PostMapping("/updateListenProcess")
	@TingshuLogin
	@Operation(summary = "更新MongoDB中用户声音的播放进度")
	public Result updateListenProcess(@RequestBody UserListenProcessVo userListenProcessVo) {
		userListenProcessService.updateListenProcess(userListenProcessVo);
		return Result.ok();

	}

	@GetMapping("/getLatelyTrack")
	@TingshuLogin
	@Operation(summary = "用户听最近一次专辑对应的声音")
	public Result getLatelyTrack() {

		Map<Object, Object> map = userListenProcessService.getLatelyTrack();

		return Result.ok(map);

	}
}

